package com.arnold.guide.sparkSql.demo02

import org.apache.spark.sql.SparkSession

/**
  * Created by arnold.zhu on 2017/7/24.
  */
object Demo02 {

  private val sparkSession: SparkSession = SparkSession.builder().master("local").appName("LearnSparkSQL").getOrCreate()

  def main(args: Array[String]): Unit = {
    val path: String = Thread.currentThread().getContextClassLoader.getResource("sparksql/demo01/people.json").getPath

    val df = sparkSession.read.json(path)

    df.printSchema()

    // 只显示Name列
    df.select("name").show()

    import sparkSession.implicits._

    // 查询name 和 age(值+1)
    df.select($"name", $"age" + 1).show()

    // 显示age>21的
    df.filter($"age" > 21).show()

    df.groupBy("age").count().show()
  }


}
